#include "led.h"

#include <QGradient>
#include <QPainter>
#include <QDebug>

static QMap<LEDCOLOR,QString> colorTrans={
    {RED,"#ff0000"},
    {GREEN,"#00ff00"}
};

void Led::resetStatus()
{
    if (blinkTimer && blinkTimer->isActive()) {
        blinkTimer->stop();
    }
    status = ON;
    setColor(GREEN);
    color = GREEN;
}

void Led::setColor(LEDCOLOR color)
{

    obj->setProperty("color", colorTrans[color]);
}

void Led::changeColor()
{
    setColor(LEDCOLOR((color+1)%2));
    color=LEDCOLOR((color+1)%2);
}

void Led::setStatus(LEDSTATES state)
{
    switch (state) {
    case ON:
        blinkTimer->stop();
        setColor(LEDCOLOR::GREEN);
        this->status = ON;
        break;

    case OFF:
        blinkTimer->stop();
        setColor(LEDCOLOR::RED);
        this->status = OFF;
        break;

    case BLINK:
        blinkTimer->start();
        this->status = BLINK;
        break;

    default:
        qDebug() << "LED - unknown states!";
    }
}

